package com.components.base.action

import android.os.Bundle
import android.os.Parcelable
import java.io.Serializable

/**参数意图*/
interface BundleAction {
    fun bundle(): Bundle?

    fun getInt(name: String): Int {
        return getInt(name, 0)
    }

    fun getInt(name: String, defaultValue: Int): Int {
        bundle()?.let {
            return it.getInt(name, defaultValue)
        }
        return defaultValue
    }

    fun getLong(name: String): Long {
        return getLong(name, 0)
    }

    fun getLong(name: String, defaultValue: Int): Long {
        bundle()?.let {
            return it.getLong(name, defaultValue.toLong())
        }
        return defaultValue.toLong()
    }

    fun getFloat(name: String): Float {
        return getFloat(name, 0)
    }

    fun getFloat(name: String, defaultValue: Int): Float {
        bundle()?.let {
            return it.getFloat(name, defaultValue.toFloat())
        }
        return defaultValue.toFloat()
    }

    fun getDouble(name: String): Double {
        return getDouble(name, 0)
    }

    fun getDouble(name: String, defaultValue: Int): Double {
        bundle()?.let {
            return it.getDouble(name, defaultValue.toDouble())
        }
        return defaultValue.toDouble()
    }

    fun getBoolean(name: String): Boolean {
        return getBoolean(name, false)
    }

    fun getBoolean(name: String, defaultValue: Boolean): Boolean {
        bundle()?.let {
            return it.getBoolean(name, defaultValue)
        }
        return defaultValue
    }

    fun getString(name: String): String {
        bundle()?.let {
            return it.getString(name).toString()
        }
        return ""
    }

    fun <P : Parcelable?> getParcelable(name: String): P? {
        bundle()?.let {
            return it.getParcelable(name)
        }
        return null
    }

    fun <S : Serializable?> getSerializable(name: String): S? {
        bundle()?.let {
            return it.getSerializable(name) as S?
        }
        return null
    }

    fun getStringArrayList(name: String): ArrayList<String>? {
        bundle()?.let { return it.getStringArrayList(name) }
        return null
    }

    fun getIntegerArrayList(name: String): ArrayList<Int>? {
        bundle()?.let { return it.getIntegerArrayList(name) }
        return null
    }
}